import {ElMessage, ElMessageBox, ElNotification} from 'element-plus'
import {MessageType} from "./webSocket";

const message = (msg: any) => {
    ElMessage({
        message:msg
    })
}
const success = (msg: any) => {
    ElMessage({
        message: msg,
        type: 'success',
    })
}
const warning = (msg: any) => {
    ElMessage({
        message: msg,
        type: 'warning',
    })
}
const error = (msg: any) => {
    ElMessage.error(msg)
}

const websocketNotify = (userName:string, msg:string, type:MessageType) => {
    (document.getElementById('audioMusic') as any).play();
    ElNotification({
        title: `来自用户${userName}的一条信息`,
        dangerouslyUseHTMLString: type == MessageType.HTML,
        message: msg,
    })
}

const notifyMessage = (msg:string) => {
    (document.getElementById('audioMusic') as any).play();
    ElNotification({
        title: '通知',
        message: msg
    })
}

const confirm = (title:string, content:string, agree:Function)=>{
    ElMessageBox.confirm(
        content,
        title,
        {
            confirmButtonText: '确定',
            cancelButtonText: '退出',
            type: 'warning',
        }
    )
        .then(() => {
            agree()
        })
}

export {message, success, warning, error, websocketNotify,confirm, notifyMessage}